package iedcyt.acute.dataAccess.dao.endnote;


import iedcyt.acute.dataAccess.domain.endnote.Discipline_Pub;
import iedcyt.acute.dataAccess.generic.SpringDao;
import iedcyt.acute.dataAccess.idao.endnote.IDiscipline_PubDao;

import java.util.List;



public class Discipline_PubDao extends SpringDao implements IDiscipline_PubDao  {

	/**
	 * @see iedcyt.acute.dataAccess.idao.endnote.IDiscipline_PubDao#create()
	 */
	@Override
	public void create() {
		//comprobamos si la tabla existe y si no la creamos
		try {
			_jdbcTemplate.queryForInt("select count(*) from Discipline_Pub");
		} catch (Exception e) {
			_jdbcTemplate.execute("CREATE TABLE Discipline_Pub (idPub numeric, idDiscipline numeric, Year varchar(10))");
		}
	}
		
	@Override
	public void deleteAll() {
		
		_jdbcTemplate.update("DELETE from Discipline_Pub");
	}

	

	@Override
	public List<Discipline_Pub> selectByIdPub(int idPub) {
		return _jdbcTemplate
		.query(
				"SELECT * FROM Discipline_Pub WHERE idPub = ?",
				new Object[] { idPub },
				new Discipline_PubRowMapper());
	}



	@Override
	public void deleteByIdPub(int idPub) {
		_jdbcTemplate.update("DELETE from Discipline_Pub WHERE idPub=?",
				new Object[] { idPub });
		
	}

	@Override
	public List<Discipline_Pub> select(Discipline_Pub dpub) {
		return _jdbcTemplate
		.query(
				"SELECT * FROM Discipline_Pub WHERE idPub = ? AND idDiscipline = ? AND Year = ?",
				new Object[] { dpub.get_idPub(), dpub.get_idDiscipline(), dpub.get_year() },
				new Discipline_PubRowMapper());
	}


	@Override
	public void insert(Discipline_Pub dpub) {
		 _jdbcTemplate.update("INSERT INTO Discipline_Pub (idPub, idDiscipline, Year) VALUES (?,?,?)",
					new Object[] { dpub.get_idPub(), dpub.get_idDiscipline(), dpub.get_year() });
		
	}

	@Override
	public void delete(Discipline_Pub discPub) {
		_jdbcTemplate.update("DELETE from Discipline_Pub WHERE idPub=? AND idDiscipline = ?",
				new Object[] { discPub.get_idPub(), discPub.get_idDiscipline() });
		
	}



	@Override
	public List<Discipline_Pub> selectAll() {
		return _jdbcTemplate.query(
				"SELECT * FROM Discipline_Pub",
				new Discipline_PubRowMapper());
	}
	

	
	
}

